<template>
  <div class="formItem">
    <el-form-item
      :prop="element.tableFieldName || element.fieldName"
      :label="selectedElement.group"
      :rules="rf_rules({required:element.fieldConfig.required, type: 'checkGroup'})"
    >
      <el-checkbox-group v-model="selects" :disabled="disabled" @change="changeSelects">
        <el-checkbox :label="item" v-for="(item, itemIndex) in selectedElement.items">{{item}}</el-checkbox>
      </el-checkbox-group>
    </el-form-item>
  </div>
</template>

<script>
  export default {
    name: 'previewSelectedItem',
    props: {
      element: {
        type: Object,
        default () {
          return {}
        }
      },
      selectedElement: {  // selected的配置
        type: Object,
        default () {
          return {}
        }
      },
      defaultValue: {
        type: Array,
        default: () => ([])
      },
      disabled: {
        type: Boolean,
        default: false
      }
    },
    data () {
      return {
        selects: this.defaultValue
      }
    },
    methods: {
      changeSelects () {
        /*let formSeletValues = this.selectedElement.items.map(item => {
          let selectObj = {}
          selectObj[item] = this.selects.indexOf(item) !== -1
          return selectObj
        })*/
        this.$emit('input', this.selects)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .formItem {
    padding: 0 10px;
    box-sizing: border-box;
  }
</style>
